package com.tms.mail.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.tms.mail.domain.Fapiao;
import com.tms.mail.service.IFapiaoService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 发票管理Controller
 *
 * @author ruoyi
 * @date 2024-11-05
 */
@RestController
@RequestMapping("/fapiao")
public class FapiaoController extends BaseController
{
    @Autowired
    private IFapiaoService fapiaoService;

    /**
     * 查询发票管理列表
     */
    @RequiresPermissions("fapiao:fapiao:list")
    @GetMapping("/list")
    public TableDataInfo list(Fapiao fapiao)
    {
        startPage();
        List<Fapiao> list = fapiaoService.selectFapiaoList(fapiao);
        return getDataTable(list);
    }

    /**
     * 导出发票管理列表
     */
    @RequiresPermissions("fapiao:fapiao:export")
    @PostMapping("/export")
    public void export(HttpServletResponse response, Fapiao fapiao)
    {
        List<Fapiao> list = fapiaoService.selectFapiaoList(fapiao);
        ExcelUtil<Fapiao> util = new ExcelUtil<Fapiao>(Fapiao.class);
        util.exportExcel(response, list, "发票管理数据");
    }

    /**
     * 获取发票管理详细信息
     */
    @RequiresPermissions("fapiao:fapiao:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(fapiaoService.selectFapiaoById(id));
    }

    /**
     * 新增发票管理
     */
    @RequiresPermissions("fapiao:fapiao:add")
    @PostMapping
    public AjaxResult add(@RequestBody Fapiao fapiao)
    {
        return toAjax(fapiaoService.insertFapiao(fapiao));
    }

    /**
     * 修改发票管理
     */
    @RequiresPermissions("fapiao:fapiao:edit")
    @PutMapping
    public AjaxResult edit(@RequestBody Fapiao fapiao)
    {
        return toAjax(fapiaoService.updateFapiao(fapiao));
    }

    /**
     * 删除发票管理
     */
    @RequiresPermissions("fapiao:fapiao:remove")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fapiaoService.deleteFapiaoByIds(ids));
    }
}
